<?php
include './main.php';
$strName = $_GET["userName"];
$strPassword = $_GET["password"];
//$strName = "test";
//$strPassword = "12345";
$ctime=date("Y-m-d H:i:s");
$utime=$ctime;
if(!preg_match("/[_\w]{6,16}/",$strPassword)){
    $code["msg"] = "密码必须为6-16位的字母数字下划线组成!";
    $res = json_encode($code);
    echo $res;
    return;
}
$sql1 = "SELECT * FROM admin WHERE username='{$strName}'";
$okk = mysqli_query($link, $sql1);
if($okk->num_rows){
    $code["msg"] = "用户名已存在！";
    $res = json_encode($code);
    echo $res;
    return;
}
$sql="insert into admin values ('{$strName}','{$strPassword}','{$ctime}','{$utime}') ";
$result = mysqli_query($link, $sql);
if($result){
    $code["status"] = true;
    $code["msg"] = "注册成功";
    $res = json_encode($code);
    echo $res;
}else{
    $code["msg"] = $link->error;
    $res = json_encode($code);
    echo $res;
}
mysqli_close($link);
?>
